package org.xinjiang.data.migration.flush.controller;

import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.xinjiang.data.migration.common.response.Result;
import org.xinjiang.data.migration.flush.service.ISettingFlushService;

import java.util.List;


@Api(tags = "设置同步刷数据")
@RestController
@RequestMapping("/setting/")
@Slf4j
public class SettingFlushController {

    @Autowired
    private ISettingFlushService flushService;


    @Operation(summary = "全量导入")
    @GetMapping(value = "pullAll")
    public Result<Integer> pullAll() {
        try {
            return flushService.pullAll();
        } catch (Exception e) {
            log.error("全量导入", e);
            throw e;
        }
    }

    @Operation(summary = "清空所有表数据")
    @GetMapping(value = "clearTabelData")
    public Result<Integer> clearTabelData() {
        try {
            return flushService.clearTabelData();
        } catch (Exception e) {
            log.error("清空所有表数据", e);
            throw e;
        }
    }

    @Operation(summary = "更新创建人修改人id-最后执行")
    @GetMapping(value = "updateCreateUpdateBy")
    public Result<Integer> updateCreateUpdateBy() {
        try {
            return flushService.updateCreateUpdateBy();
        } catch (Exception e) {
            log.error("清空所有表数据", e);
            throw e;
        }
    }

    @Operation(summary = "创建用户部门关系表-会清空原有关系")
    @GetMapping(value = "updateCreateUserDerart")
    public Result<Integer> updateCreateUserDerart() {
        try {
            return flushService.updateCreateUserDerart();
        } catch (Exception e) {
            log.error("清空所有表数据", e);
            throw e;
        }
    }


    @Operation(summary = "部门数据")
    @GetMapping(value = "depart")
    public Result<Integer> depart(@RequestParam(required = false) List<String> ids) {
        try {
            return flushService.depart(ids);
        } catch (Exception e) {
            log.error("部门数据", e);
            throw e;
        }
    }


    @Operation(summary = "部门数据子父级关系")
    @GetMapping(value = "departParent")
    public Result<Integer> departParent(@RequestParam(required = false) List<String> ids) {
        try {
            return flushService.departParent(ids);
        } catch (Exception e) {
            log.error("部门数据子父级关系", e);
            throw e;
        }
    }


    @Operation(summary = "用户数据")
    @GetMapping(value = "user")
    public Result<Integer> user(@RequestParam(required = false) List<String> ids) {
        try {
            return flushService.user(ids);
        } catch (Exception e) {
            log.error("用户数据", e);
            throw e;
        }
    }


    @Operation(summary = "工作人员")
    @GetMapping(value = "workingPersonnel")
    public Result<Integer> workingPersonnel(@RequestParam(required = false) List<String> ids, @RequestParam(required = false, defaultValue = "true") boolean increment) {
        try {
            return flushService.workingPersonnel(ids, increment);
        } catch (Exception e) {
            log.error("工作人员", e);
            throw e;
        }
    }

    @Operation(summary = "社会工作者")
    @GetMapping(value = "socialWorker")
    public Result<Integer> socialWorker(@RequestParam(required = false) List<String> ids, @RequestParam(required = false, defaultValue = "true") boolean increment) {
        try {
            return flushService.socialWorker(ids, increment);
        } catch (Exception e) {
            log.error("社会工作者", e);
            throw e;
        }
    }

    @Operation(summary = "志愿者")
    @GetMapping(value = "volunteer")
    public Result<Integer> volunteer(@RequestParam(required = false) List<String> ids, @RequestParam(required = false, defaultValue = "true") boolean increment) {
        try {
            return flushService.volunteer(ids, increment);
        } catch (Exception e) {
            log.error("志愿者", e);
            throw e;
        }
    }
}
